﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="quiz-add.aspx.cs" Inherits="VQWEB.administrator.huongnghiep.quiz.quiz_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frmObjects" action="" method="post">
    <div class="row">
    <div id="dileft" class="col-md-8"></div>
    <div id="diright" class="col-md-4">
    </div>
    </div>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/huongnghiep/quiz/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';
        $(document).ready(function () {
        $.get(url_ashx, { view_quiz: "view_quiz", Id: GetId() }, function (data) {
                var parse = $.parseJSON(data);
                var chuyennganh = parse.chuyennganh;
                var array_chuyennganh;
                if (CheckAtionInPath("add")) {
                    array_chuyennganh = array_checkbox(chuyennganh);
                    loadform(0, "", "", false, array_chuyennganh);
                }
                else if (CheckAtionInPath("edit")) {
                    var quiz = parse.quiz;
                    var chuyennganh = parse.chuyennganh;
                    var array_chuyennganh = array_checkbox(chuyennganh);
                    loadform(quiz.id,quiz.value,quiz.noidung, quiz.active, array_chuyennganh);
                }
            });
        });

        function loadform(id, value, noidung, active, array_chuyennganh) {
            $.jqoteload(url_input, function (tmpl) {
                $("#diright").multiple("groupcheckbox", null, array_chuyennganh, "Chuyen nganh:", tmpl.input_tpl);
                $("#dileft").single("hidden", "quiz_id", id, null, null, tmpl.input_tpl);
                $("#dileft").single("text", "quiz_value", value, "Giá trị:", null, tmpl.input_tpl);
                $("#dileft").single("editor", "quiz_noidung", noidung, "Nội dung:", null, tmpl.input_tpl);
                $("#dileft").single("checkbox", "quiz_active", true, "Kích hoạt", active, tmpl.input_tpl);
                tinymce.init({ selector: 'textarea#tinymce' });
                $("#frmObjects").validate({
                    rules: { quiz_value: { required: true }},
                    messages: { quiz_value: { required: null } }
                });
            });

        }


        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/huongnghiep/quiz/list";
        });
        $(document).on("click", "#btnSave", function () {
            if ($("#frmObjects").valid()) {
                var value = tinymce.get('tinymce').getContent();
                $("textarea[name='quiz_noidung']").val(value);
                var arr = $("#frmObjects").serializeObject();
                $.post(url_ashx, { add_quiz: window.escape(arr) }, function (data) {
                    alert(data);
                    window.location = "/admin/huongnghiep/quiz/list";
                });
            }
        });
    </script>
</asp:Content>
